//
//  netWorkManager.swift
//  WeiBo_NB
//
//  Created by apple on 15/3/4.
//  Copyright (c) 2015年 Ai. All rights reserved.
//

import Foundation
import SampleNetWorks

class netWorkManager {
    
    // 单例，内存中有一个唯一的实例，并且能提供唯一的全局访问入口
    static let sharedManager = netWorkManager()
    private let net = SampleNeworks()
    
    
    // 定义了一个类的完成闭包类型
    typealias Completion = (result: AnyObject?, error: NSError?) -> ()
    
    
    
    
    
    ///  缓存路径
    ///
    ///  :param: urlString 图片地址
    ///
    ///  :returns: 对应图片在缓存中得路径
    func fullPath(urlString:String)->String{
        return net.fullPath(urlString)
    }
    
    
    ///  异步加载数据
    ///
    ///  :param: urlString  图片网址
    ///  :param: completion 回调
    func requestImage(urlString:String,completion:Completion)->(){
        net.requestImage(urlString, completion: completion)
    }
    
    ///  请求Json
    ///
    ///  :param: method     请求方法
    ///  :param: urlString  urlString
    ///  :param: params     可选字典参数
    ///  :param: completion 回调---闭包
    func requestJSON(method: HTTPMethod, _ urlString: String, _ params: [String: String]?, completion: Completion) {
        
        net.requestJson(method, urlString: urlString, params: params, completion: completion)
    }
    
    ///  下载多张图片
    ///
    ///  :param: urlStrings 图片数组
    ///  :param: completion 回调
    func downloadImages(urls:[String],completion:Completion)->(){
        net.downloadImages(urls, completion: completion)
    }

    

}